// pages/withdraw/withdraw.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      options:options
    })
  },
  onShow: function () {
  
  },
  input:function(res){
    var that = this;
    var value = res.detail.value;
    var num = res.detail.cursor;
    that.setData({
      num:num,
      value:value
    })
  },
  //提现
  submit:function(){
    var that = this;
    if (that.data.value > parseInt(that.data.options.money) || !/^\d+(\.\d+)?$/.test(that.data.value)){
      wx.showModal({
        title: '提示',
        content: '请输入正确的金额',
      })

      console.log(that.data.options.money);
      console.log(that.data.value);
    }else{
      app.getLoginSession(function (session) {
        wx.request({
          url: app.api +'/WithdrawCash/applyCash',
          data:{
            price:that.data.value,
            t_session:session
          },
          success:function(res){
            var res = res.data;
            if(res.done){
              wx.showModal({
                title: '温馨提示',
                content: '您的提现申请已经提交成功',
              })
              that.data.options.money=that.data.options.money-that.data.value;
              that.setData({
                options:that.data.options
              })
            }else{
              wx.showToast({
                title: '失败，请重试！',
              })
            }
          },
          fail:function(res){
            wx.showToast({
              title: '失败，请重试！',
            })
          }
        })
    })
    }
  },
  //全部提现
  allmoney:function(res){
    this.setData({
      value:this.data.options.money
    })
  }
})